import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_magic_planet/common/constant.dart';
import 'package:flutter_magic_planet/component/webview_page.dart';
import 'package:get/get.dart';

import 'block_button.dart';

class PrivacyDialog extends StatefulWidget {
  final VoidCallback? onTap;

  const PrivacyDialog({Key? key, this.onTap}) : super(key: key);
  @override
  _PrivacyDialogState createState() => _PrivacyDialogState();
}

class _PrivacyDialogState extends State<PrivacyDialog> {
  TapGestureRecognizer? _tapGestureRecognizer;

  @override
  void initState() {
    _tapGestureRecognizer = TapGestureRecognizer()
      ..onTap = () {
        Get.to(WebViewPage(url: privacyUrl));
      };
    super.initState();
  }

  @override
  void dispose() {
    _tapGestureRecognizer!.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: paddingHorizontal),
      child: Column(
        children: [
          SizedBox(height: 12),
          Container(
            alignment: Alignment.center,
            padding: EdgeInsets.symmetric(horizontal: 20),
            child: RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                    text: '我们承诺，绝不收集用户信息，保护隐私从我们做起！\n您可阅读',
                    style: TextStyle(color: Colors.black54, fontSize: 15),
                  ),
                  TextSpan(
                    recognizer: _tapGestureRecognizer,
                    text: '《隐私协议》',
                    style: TextStyle(color: Colors.blue, fontSize: 15),
                  ),
                  TextSpan(
                    text: '了解详情。如您同意，请点击"同意"开始使用。',
                    style: TextStyle(color: Colors.black54, fontSize: 15),
                  )
                ],
              ),
            ),
          ),
          SizedBox(height: 32),
          Container(
            margin: EdgeInsets.symmetric(horizontal: 18),
            child: BlockButton(
              color: primaryColor,
              title: '同意',
              onTap: widget.onTap,
            ),
          ),
          SizedBox(height: 12),
          GestureDetector(
            child: Text(
              '不相信',
              style: TextStyle(color: Colors.black54, fontSize: 14),
            ),
            onTap: () {
              exit(0);
            },
          ),
        ],
      ),
    );
  }
}
